package com.ysw.rpc.client.handler.initializer;

import com.ysw.rpc.client.config.ClientProperties;
import com.ysw.rpc.client.handler.inbound.ResponseHandler;
import com.ysw.rpc.common.config.MessageCodec;
import com.ysw.rpc.common.config.MessageLengthFieldDecoder;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioSocketChannel;

/**
 * 客户端初始化
 *
 * @author YinShangwen
 * @since 2023/4/4 14:31
 */

@ChannelHandler.Sharable
public class ClientInitializerHandler extends ChannelInitializer<NioSocketChannel> {
    private final ClientProperties clientProperties;

    public ClientInitializerHandler(ClientProperties clientProperties) {
        this.clientProperties = clientProperties;
    }

    @Override
    protected void initChannel(NioSocketChannel ch) {
        ch.pipeline().addLast(new MessageLengthFieldDecoder(), new MessageCodec(clientProperties), new ResponseHandler(clientProperties));
    }
}
